package com.zoweunion.mechanic.controller.api;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.zoweunion.mechanic.model.User;
import com.zoweunion.mechanic.service.app.TSSsHumanfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.entity.TSSsHumanfaceEntity;


import com.zoweunion.mechanic.model.ResponseBean;
import com.github.pagehelper.PageInfo;
import javax.servlet.http.HttpServletRequest;



/**
 * 
 *
 * @author xp
 * @email 17688825585@163.com
 * @date 2020-05-28 20:06:27
 */
@RestController
@RequestMapping("/tssshumanface")
public class TSSsHumanfaceController extends BaseController {
    @Autowired
    private TSSsHumanfaceService tSSsHumanfaceService;

    /**
     * 列表
     */
    @GetMapping("/tSSsHumanfaceList")
    public ResponseBean tSSsHumanfaceList(@RequestParam Map<String, Object> params, HttpServletRequest request)  throws MyException{
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        PageInfo info = tSSsHumanfaceService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增
     */
    @PostMapping("/tSSsHumanfaceInsertUpdate")
    public ResponseBean tSSsHumanfaceInsertUpdate(@RequestBody TSSsHumanfaceEntity params,
                                             HttpServletRequest request) throws MyException{
        String userId = getCurrentUser(request).getId();
        Date date = new Date();
        if (params.getId()!=null){
                logger.info("修改人脸识别");
                params.setUpdateTime(date);
                params.setUpdateUser(userId);
                tSSsHumanfaceService.updateById(params);
        }else {
                logger.info("新增人脸识别");
                params.setCreateUser(userId);
                params.setCreateTime(date);
                tSSsHumanfaceService.save(params);
        }
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }
    @PostMapping("/deleteTSSsHumanface")
    public ResponseBean deleteTSSsHumanface(@RequestBody TSSsHumanfaceEntity params, HttpServletRequest request)  throws MyException{
        logBefore(logger,"删除人脸识别");
        Long id = params.getId();
        int result = tSSsHumanfaceService.deleteTSSsHumanfaceById(id);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", result);
    }

    /**
     * 获取人脸识别物联网卡号列表
     * @param request
     * @return
     * @throws MyException
     */
    @GetMapping("/getThingsList")
    public ResponseBean getThingsList(HttpServletRequest request)  throws MyException{
        logBefore(logger,"获取人脸识别物联网卡号列表");
        List<String> thingsList = tSSsHumanfaceService.getThingsList();
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", thingsList);
    }







}
